var t = require("../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        cancelInfo: {},
        isSubmitted: !1,
        checked: !1,
        showConfirm: !1,
        showMobileVerification: !1,
        bindMobile: !1,
        imgCaptcha: !1,
        country: "",
        captcha: "",
        mobile: "",
        code: "",
        count: ""
    },
    onLoad: function(t) {},
    onShow: function() {
        this.getData();
    },
    getData: function() {
        var t = this, a = e.getNetAddresss("member.cancel.getSet");
        e._getNetWork({
            url: a,
            success: function(e) {
                1 !== e.data.result && wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                }), e.data.data.set && e.data.data.set.content && (e.data.data.set.content = t.replaceDetail(e.data.data.set.content)), 
                t.setData({
                    cancelInfo: e.data.data.set,
                    isSubmitted: !!e.data.data.set && e.data.data.set.is_record,
                    bindMobile: !!e.data.data.set && e.data.data.set.is_bind_mobile
                });
            }
        });
    },
    replaceDetail: function(t) {
        for (var e = ""; -1 != t.indexOf("<img"); ) e += t.substring("0", t.indexOf("<img") + 4), 
        -1 != (t = t.substring(t.indexOf("<img") + 4)).indexOf("style=") && t.indexOf("style=") < t.indexOf(">") ? (e += t.substring(0, t.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;", 
        t = t.substring(t.indexOf('style="') + 7)) : e += ' style="max-width:100%;height:auto;margin:0 auto;" ';
        return e += t;
    },
    submit: function() {
        var t = this;
        this.data.checked ? 1 != this.data.cancelInfo.tel_status || this.data.bindMobile ? 1 == this.data.cancelInfo.tel_status ? (this.getCaptcha(), 
        this.setData({
            showMobileVerification: !0
        })) : this.setData({
            showConfirm: !0
        }) : wx.showModal({
            title: "提示",
            content: "暂未绑定手机号, 请先绑定手机号",
            success: function(e) {
                e.confirm && (wx.navigateTo({
                    url: "/packageA/member/editmobile/editmobile?num=" + t.data.mobile + "&fromApp=2&editType=0"
                }), wx.setStorage({
                    key: "isset",
                    data: 1
                }));
            }
        }) : wx.showToast({
            title: "请先阅读申请协议并确认",
            icon: "none"
        });
    },
    getCaptcha: function() {
        var t = this, a = e.getNetAddresss("home-page.getCaptcha");
        e._getNetWork({
            url: a,
            success: function(e) {
                1 === e.data.result ? t.setData({
                    imgCaptcha: e.data.data.captcha.img
                }) : wx.showToast({
                    title: e.data.msg
                });
            }
        });
    },
    sendCode: function() {
        var t = this;
        if (this.data.cancelInfo.country_code && e._isTextEmpty(this.data.country)) wx.showModal({
            content: "请输入国际区号",
            showCancel: !1
        }); else if (e._isTextEmpty(this.data.mobile)) wx.showModal({
            content: "请填写手机号",
            showCancel: !1
        }); else if (this.data.imgCaptcha && e._isTextEmpty(this.data.captcha)) wx.showModal({
            content: "请填图形验证码",
            showCancel: !1
        }); else {
            wx.showLoading({
                title: "loading"
            });
            // var a = e.getNetAddresss("member.register.sendCodeV2");
            var a = e.getNetAddresss("SMS.index");
            e._getNetWork({
                url: a,
                data: {
                    reset: 1,
                    sms_type: 0,
                    mobile: this.data.mobile,
                    state: this.data.country,
                    captcha: this.data.captcha
                },
                success: function(e) {
                    if (wx.hideLoading(), 1 === e.data.result) {
                        wx.showToast({
                            title: "发送成功"
                        });
                        var a = 60;
                        t.timer || (t.setData({
                            count: a
                        }), t.timer = setInterval(function() {
                            t.data.count > 0 && t.data.count <= a ? t.setData({
                                count: --a
                            }) : (clearInterval(t.timer), t.timer = null);
                        }, 1e3));
                    } else t.getCaptcha(), wx.hideLoading(), wx.showModal({
                        content: e.data.msg,
                        showCancel: !1
                    });
                },
                fail: function(t) {
                    wx.hideLoading();
                }
            });
        }
    },
    checkCode: function() {
        var t = this;
        if (e._isTextEmpty(this.data.mobile)) wx.showModal({
            content: "请填写手机号",
            showCancel: !1
        }); else if (e._isTextEmpty(this.data.code)) wx.showModal({
            content: "请填写验证码",
            showCancel: !1
        }); else {
            var a = e.getNetAddresss("member.register.checkCode");
            e._getNetWork({
                url: a,
                data: {
                    mobile: this.data.mobile,
                    code: this.data.code
                },
                success: function(e) {
                    1 !== e.data.result ? wx.showModal({
                        content: e.data.msg,
                        showCancel: !1
                    }) : t.setData({
                        showConfirm: !0
                    });
                }
            });
        }
    },
    cancelPost: function() {
        var t = this, a = e.getNetAddresss("member.cancel.index");
        wx.showLoading({
            title: "loading"
        }), e._getNetWork({
            url: a,
            success: function(e) {
                wx.hideLoading(), 1 !== e.data.result ? wx.showModal({
                    content: e.data.msg,
                    showCancel: !1
                }) : (wx.showToast({
                    title: e.data.msg
                }), t.setData({
                    isSubmitted: !0
                }));
            },
            fail: function() {
                wx.hideLoading();
            }
        });
    },
    confirmCancel: function() {
        this.cancelPost(), this.closeConfirmPopup();
    },
    closeConfirmPopup: function() {
        this.setData({
            showConfirm: !1
        });
    },
    back: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    revoke: function() {
        var t = this, a = e.getNetAddresss("member.cancel.cancel");
        wx.showLoading({
            title: "loading"
        }), e._getNetWork({
            url: a,
            success: function(e) {
                wx.hideLoading(), 1 === e.data.result ? (wx.showToast({
                    title: "撤销成功",
                    icon: "none"
                }), t.initData(), t.getData()) : wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function() {
                wx.hideLoading();
            }
        });
    },
    initData: function() {
        this.setData({
            cancelInfo: {},
            isSubmitted: !1,
            checked: !1,
            showConfirm: !1,
            showMobileVerification: !1,
            bindMobile: !1,
            country: "",
            captcha: "",
            mobile: "",
            code: "",
            count: ""
        });
    },
    changeInput: function(e) {
        var a = e.currentTarget.dataset.key;
        this.setData(t({}, "".concat(a), e.detail));
    },
    onAgree: function(t) {
        this.setData({
            checked: t.detail
        });
    },
    inpMobile: function(t) {
        this.setData({
            mobile: t.detail
        });
    },
    inpCode: function(t) {
        this.setData({
            code: t.detail
        });
    }
});